package bidsanity

import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class BidServiceIntegrationTests {

    def bidder = new Customer(emailAddress: 'seller@example.org', password: "testing")
    def seller = new Customer(emailAddress: 'winner@example.org', password: "testing")
    def listing
    def bidService = new BidService()

    @Before
    void setUp() {
        // Setup logic here
        bidder.save()
        seller.save()
        listing = new Listing(
                name: 'TestListing',
                endDate: new Date() + 10,
                startingBidPrice: 1.0D,
                description: 'a test listing',
                seller: seller).save()
    }

    @After
    void tearDown() {
        // Tear down logic here
    }

    @Test
    void testCreateBadBid() {
        Assert.assertNotNull(bidder.id)
        Assert.assertNotNull(seller.id)
        Assert.assertNotNull(listing.id)

        def b = bidService.createBid(amount: 2.0D, listingId: listing.id)
        Assert.assertNull(b.bidder)
        Assert.assertNotNull(b)
        Assert.assertNull(b.id)
        Assert.assertTrue(listing.hasErrors())
    }
}
